/**
 *
 */
package com.naiterui.ehp.bs.patient.controller;

import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.context.ResourceHolder;
import com.naiterui.ehp.bp.support.security.SettingConfig;
import com.naiterui.ehp.bs.patient.service.IPatientService;
import com.naiterui.ehp.bs.patient.utils.exception.PatientBusinessException;
import com.naiterui.ehp.bs.patient.vo.DeviceVerifyVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 设备校验
 *
 * @author guoyongxiang
 * @since 1.0.0
 */
@Api(tags = {SwaggerTag.PATIENT + SwaggerTag.USER_ACCOUNT})
@RequestMapping("ap/device")
@RestController
public class ApDeviceVerifyController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ApDeviceVerifyController.class);

    @Autowired
    private IPatientService patientService;

    @ApiOperation(value = "登录设备校验(登录互踢)", notes = "传入设备标识校验是否与上次登录设备不同(每次登录后或切换前台时调用)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientId", value = "患者ID", dataType = "Long", paramType = "query", required = true),
            @ApiImplicitParam(name = "deviceSN", value = "设备编号(设备唯一标识)", dataType = "Long", paramType = "query", required = true),
            @ApiImplicitParam(name = "_model", value = "机型", dataType = "Long", paramType = "query"),
    })
    @RequestMapping("verify")
    public DeviceVerifyVO verify(Long patientId, String deviceSN,
                                 @RequestHeader(required = false, name = "_model") String model) throws PatientBusinessException {
        if (null == patientId) {
            patientId = (Long) ResourceHolder.getResource(SettingConfig.PATIENT_ID);
        }

        LOGGER.info("into the method verify 请求参数：patientId = [{}], deviceSN = [{}], _model = [{}]", patientId, deviceSN, model);
        return this.patientService.getVerifyInfo(patientId, deviceSN);
    }
}
